package com.example.warehouse.service.serviceImpl;

import com.example.warehouse.Vo.StoreCountVo;
import com.example.warehouse.entity.Store;
import com.example.warehouse.mapper.StoreMapper;
import com.example.warehouse.page.Page1;
import com.example.warehouse.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@CacheConfig(cacheNames = "com.example.warehouse.service.serviceImpl.StoreServiceImpl")
@Service
public class StoreServiceImpl implements StoreService{
    @Autowired
    private StoreMapper storeMapper;


    @Override
    @Cacheable(key = "'all:store'")
    public List<Store> findAllStore() {
        return storeMapper.findAllStore();
    }

    @Override
    public Page1 QueryPage(Store store, Page1 page1) {
        int count = storeMapper.findCount(store);
        List<Store> storeList = storeMapper.QueryPage(store, page1);
        page1.setResultList(storeList);
        page1.setPageNum(count);
        return page1;
    }

    @Override
    public void addStore(Store store) {
        storeMapper.addStore(store);
    }

    @Override
    public void deleteStore(Integer storeId) {
        storeMapper.deleteStore(storeId);
    }

    @Override
    public void updateStore(Store store) {
        storeMapper.updateStore(store);
    }

    @Override
    public List<StoreCountVo> queryStoreCount() {

        return storeMapper.findStoreCount();
    }


}
